package com.dream.tihai.controller;

import com.dream.tihai.dto.TreeTypeDto;
import com.dream.tihai.service.ITypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Valley
 * Created by Valley on 2022/12/14
 */
@RequestMapping("type")
@RestController
@CrossOrigin
public class TypeController {

    @Autowired
    ITypeService typeService;

    @RequestMapping("selectTreeNode")
    public List<TreeTypeDto> selectTreeNode() throws Exception {
        List<TreeTypeDto> typeDtos = typeService.selectTreeNode();
        return typeDtos;
    }

    @RequestMapping("addChildType")
    public long addChildType(String pName, String nodeName) throws Exception {
        long id = typeService.addChildNode(pName, nodeName);
        return id;
    }

    @RequestMapping("removeType")
    public String removeType(String name) throws Exception {
        boolean result = typeService.removeType(name);
        return "ok";
    }



}
